﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Communergy.Common;

namespace Communergy.Repository.InMemory
{
    public class InMemoryMeterRepository : IMeterRepository
    {

        InMemoryUnitOfWork unitOfWork;

        public InMemoryMeterRepository(IUnitOfWork unitOfWork)
        {
            this.unitOfWork = unitOfWork as InMemoryUnitOfWork;
        }

        #region IMeterRepository Members

        public void CreateNewMeter(Meter meterToCreate)
        {
            unitOfWork.AddMeter(meterToCreate);
        } 


        public Meter RetrieveMeterDetails(string meterId)
        {
            
            var meter = unitOfWork.Meters.Where(m => m.MeterId == meterId).FirstOrDefault();
            return meter;
        }


        public void AddSourceToMeter(Meter meter, MeterSource meterSource)
        {
            var thisMeter = RetrieveMeterDetails(meter.MeterId);
            unitOfWork.AddMeterSource(thisMeter, meterSource);
        }

        public void SaveMeterDetails(Meter meterToSave)
        {
            throw new NotImplementedException();
        }

        public List<Meter> GetMetersForUser(string userId)
        {
            throw new NotImplementedException();
        }

       
        public MeterSource RetrieveSourceDetails(string sourceId)
        {
            var source = unitOfWork.RetrieveSourceDetails(sourceId);
            return source;
        }

        #endregion
    }
}
